package cn.lang.oss;

import cn.lang.oss.factory.IOssFactory;
import cn.lang.oss.factory.QiniuOssFactory;

import java.io.File;

/**
 * @ClassName : OssKit
 * @Description :
 * @Author : Lang
 * @Date: 2020-03-07 13:30
 */
public class OssKit {

    private static IOssFactory defaultOssFactory;

    private static Oss oss;

    static {
        init();
    }

    private static void init(){

        if (defaultOssFactory == null) {
            defaultOssFactory = new QiniuOssFactory();
        }
        if(oss == null){
            oss = defaultOssFactory.getOss();
        }
    }

    public static void setDefaultOssFactory(IOssFactory defaultOssFactory){
        if (defaultOssFactory == null) {
            throw new IllegalArgumentException("defaultOssFactory can not be null.");
        }
        OssKit.defaultOssFactory = defaultOssFactory;
    }

    public static void setOss(Oss oss) {
        if (oss == null) {
            throw new IllegalArgumentException("oss can not be null.");
        }
        OssKit.oss = oss;
    }

    public static String upload(File targetFile){
        return  oss.upload(targetFile);
    }

    public static String upload(File targetFile, String resourcesName){
        return  oss.upload(targetFile,resourcesName);
    }

    public static String upload(String targetName, String resourcesName){
        return  oss.upload(targetName,resourcesName);
    }

    public static String upload(byte[] data,String targetName){
        return  oss.upload(data,targetName);
    }




}
